<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>厂商列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<!-- 是否显示启用禁用按钮 -->
<sys:funcAuth resCd="disable">
	<span id="isDisableBtn" />
</sys:funcAuth>
<!-- 是否显示修改按钮 -->
<sys:funcAuth resCd="modify">
	<span id="isModifyBtn" />
</sys:funcAuth>
<!-- 是否显示删除按钮 -->
<sys:funcAuth resCd="delete">
	<span id="isDeleteBtn" />
</sys:funcAuth>
<!-- 是否显示新增厂商按钮 -->
<sys:funcAuth resCd="add">
	<span id="isAddBtn" />
</sys:funcAuth>

<script type="text/javascript">
	var grid = null;
	$(function () {
	    $("#ligergrid1").ligerGrid({
	    	url: '<%=path%>/product/mfrInfo/initList.do',
	    	method : 'get',
	        columns: [
	            { display: '厂商名称',align: 'left',width: 250, 
		            render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:toMfrDetail(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">'+rowdata.mfrNm+'</a>'
	                return h;
            	}
	            },
	            { display: '厂商传真', name: 'mfrFax', width: 150 },
	            { display: '厂商电话', name: 'mfrTel', width: 150},
	            { display: '使用状态', name: 'isValidNm', width: 120 },
                { display: '放款方式', name: 'payTypCdNm', width: 120 },
	            /* { display: '审核状态', name: 'audStsCdNm', width: 120 }, */
	            { display: '操作', width: 200 ,align:'left', 
	            	render: function (rowdata, rowindex, value){
	            		var v;
                        var v1='<a class="sq-button-hasicon" href="javascript:;" onclick="disable(';
                            v1+="'"+rowdata.id+"'";
                            v1+=')"><i class="sqBtnIco_13"></i>'+LogUtils.LOG_CMM_GRID_BTN_DISABLE+'</a>';
                            
                        var v2='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
                            v2+="'"+rowdata.id+"'";
                            v2+=')"><i class="sqBtnIco_12"></i>'+LogUtils.LOG_CMM_GRID_BTN_ENABLE+'</a>';
                    	switch (rowdata.isValid){
                           case 0:
                               v=v2;
                               break;
                           case 1:
                               v=v1;
                               break;
                           default:
                           	v=v1;
                           	break;
                        }
	            		var h='<a class="sq-button-hasicon" href="javascript:toMfrModify(';
		            		h+="'"+rowdata.id+"'";
		                    h+=')"><i class="sqBtnIco_4"></i>修改</a>';
	            		var d='<a class="sq-button-hasicon" href="javascript:deleteRecord(';
		            		d+="'"+rowdata.id+"'";
		                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
		                    
	                    var isDisableBtn = $("#isDisableBtn");
	                    var modify = $("#isModifyBtn");
	                    var deletes = $("#isDeleteBtn");
	                    var end = "";
	                   if (modify.length) {
	                    	 end += h;
	                    }
	                    if (deletes.length) {
	                    	 end += d;
	                    } 
	                    if (isDisableBtn.length) {
	                    	 end += v;
	                    }
		                    
	                	return end;
	            	}
	            },
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        checkbox:true,
	        rownumbers:true,
	        /* onRenderComplete: function () {
	        	iframeResize ();
	        } */
	        onAfterShowData: function () {
	            $(".gridTip").grid_ligerTip();
	            SetIframe_height ();
	        }
	    });
	    grid = liger.get("ligergrid1");
	    grid.setHeight(100);
	    $("#searchBar").ligerForm();
	
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         data["crtTm"] = $("#crtTm").val();
	         //alert(JSON.stringify(data));
	         for (name in data){
	            grid.setParm(name,data[name]);
	         };
	        grid.reload();
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	        var form = liger.get("searchBar");
	        form.setData({  //重置select等特殊表单
	            "orgCd": "-1"
	        });
	    });
	    
	    $("#pageloading").hide();
	    addButtonShow();
	});
	
	var callback = function () {
		grid.reload();
    };
	 //新增数据
	function add(){
        Add_navTab("PrdMfr_1"+Date.parse(new Date()), "新增厂商", '<%=path%>/product/mfrInfo/toAddPage.do', callback);
	}
	//删除数据
	function deleteRecord(id){
		if(!id)return;
		var _ids = [];
		_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM+"厂商下产品也会级联删除！", function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/product/mfrInfo/removeByIds.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	
	function addButtonShow (){
		var add = $("#isAddBtn");
		if (add.length == 0) {
			document.getElementById('addBtn').style.display="none";
		}
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
	function toMfrDetail(_id){
		if(!_id || _id=="")return;
		parent.mainApp.f_addTab('PrdMfr_3'+_id,'厂商详情','<%=path%>/product/mfrInfo/toDetailPage.do?id='+_id);
	}
	var callback = function () {
		grid.reload();
    };
	function toMfrModify(_id){
		if(!_id || _id=="")return;
		Add_navTab('PrdMfr_2'+_id, "修改厂商", '<%=path%>/product/mfrInfo/toAddPage.do?id='+_id, callback);
	}
	//启用
	function enable(id){
		if(!id)return;
		$.ligerDialog.confirm(LogUtils.LOG_CMM_ENABLE_CONFIRM, function (flag) {
   			if(flag == false)return;
   			var wait_dialog;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:{id:id},
   				url: '<%=path%>/product/mfrInfo/enable.do',
   				beforeSend: function(){
   			     wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type:"waitting"});
   			    },
   				success:function(msg){
   					wait_dialog.close();
   					 if(msg.success == 1){
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
   						 grid.reload();
   					 }else{
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
   					 }
   				}
   			});
   		});
	}
	//禁用
	function disable(id){
		if(!id)return;
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
   			if(flag == false)return;
   			var wait_dialog;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:{id:id},
   				url: '<%=path%>/product/mfrInfo/disable.do',
   				beforeSend: function(){
   			     wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type:"waitting"});
   			},

   				success:function(msg){
   					wait_dialog.close();
   					 if(msg.success == 1){
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
   						 grid.reload();
   					 }else{
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
   					 }
   				}
   			});
   		});
	}
	
</script>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
            <div class="fieldBox">
                <div class="label">厂商名称</div>
                <div class="field">
                    <input name="mfrNm" id="mfrNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">厂商地址</div>
                <div class="field">
                    <input name="mfrAddr" id="mfrAddr" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round">查询</span>
               <span id="clearBtn" class="sq-button sq-button-round">清空</span>
               <span id="addBtn" class="sq-button sq-button-round" onclick="add();">新增厂商</span>
               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>


</body>
</html>